package com.example.wechat.service;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.widget.Toast;
import com.example.wechat.model.PaymentResult;
import java.util.concurrent.TimeUnit;

public class PaymentService {
    public interface PaymentCallback {
        void onSuccess(PaymentResult result);
        void onFailure(String error);
    }

    public void processPayment(Context context, String amount, String paymentMethod, PaymentCallback callback) {
        // 模拟支付过程
        new Handler(Looper.getMainLooper()).postDelayed(() -> {
            // 模拟80%的成功率
            if (Math.random() < 0.8) {
                PaymentResult result = new PaymentResult(
                    System.currentTimeMillis(),
                    amount,
                    paymentMethod,
                    generateOrderNumber()
                );
                callback.onSuccess(result);
            } else {
                callback.onFailure("支付失败，请重试");
            }
        }, 2000);
    }

    private String generateOrderNumber() {
        return String.format("%d%06d", System.currentTimeMillis(), (int)(Math.random() * 1000000));
    }
} 